package server.gui;

import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;

import server.exception.ServiceException;
import server.services.ServerService;

@SuppressWarnings("serial")
public class PantallaDetenerServidor extends JFrame {

	private JPanel contentPane;
	private final JButton btnEnviarYDetener = new JButton("Enviar y deneter");
	private final JButton btnCancelar = new JButton("Cancelar");
	private JLabel label;
	private JLabel label_1;
	private ServerService service;
	private JTextArea textAreaMensajeDeDetencion;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					PantallaDetenerServidor frame = new PantallaDetenerServidor();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public PantallaDetenerServidor() {
		service = new ServerService();
		setTitle("Detener Servidor");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 547, 229);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		label = new JLabel("");
		label.setBounds(258, 21, 0, 0);
		contentPane.add(label);
		btnEnviarYDetener.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					service.parar(textAreaMensajeDeDetencion.getText());
				} catch (ServiceException e) {
					JOptionPane.showMessageDialog(null, "Ocurrio un problema al parar el servicio\n" +e.getMessage()
							, "Error", JOptionPane.ERROR_MESSAGE);
					e.printStackTrace();
				}
			}
		});
		btnEnviarYDetener.setBounds(10, 149, 140, 23);
		contentPane.add(btnEnviarYDetener);
		
		textAreaMensajeDeDetencion = new JTextArea();
		textAreaMensajeDeDetencion.setBounds(10, 41, 511, 92);
		contentPane.add(textAreaMensajeDeDetencion);
		btnCancelar.setBounds(432, 149, 89, 23);
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				cancelar();
			}
		});
		contentPane.add(btnCancelar);
		
		label_1 = new JLabel("");
		label_1.setBounds(460, 21, 0, 0);
		contentPane.add(label_1);
		
		JLabel lblIngreseSuMensaje = new JLabel("Ingrese su mensaje");
		lblIngreseSuMensaje.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblIngreseSuMensaje.setBounds(21, 11, 284, 24);
		contentPane.add(lblIngreseSuMensaje);
	}
	
	private void cancelar() {
		this.dispose();
	}
}
